#ifndef DATABASEWORKER_H
#define DATABASEWORKER_H

#include<QThread>
#include<QtSql>

class SongData;

class DatabaseWorker: public QThread{
Q_OBJECT
public:
	DatabaseWorker(QSqlDatabase *db, QList<SongData*> songs, QObject *parent);
	~DatabaseWorker();
	
	virtual void run();
	
	void addSongs(QList<SongData*> data);
	QSet<QString> changedArtists()const{ return m_changedArtists; }
private:
	QSqlDatabase *m_db;
	QList<SongData*> m_songs;
	QList<SongData*> m_currentSongs;
	QSet<QString> m_changedArtists;
	
	static void _songData(SongData *songData, char *out, char *buf = 0, int buflen = 0);
	static void _safeString(const QString &string, char *out);
	void _tryAgainOnError();
};

#endif
